package com.example;

import com.example.dao.DeviceDao;
import com.example.domain.Device;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;

/**
 * 功能描述: TODO <br/>
 * 创建时间: 2016/9/27<br/>
 *
 * @author QiuYang
 */
@Path("device")
public class DeviceResource {
    private final DeviceDao deviceDao;

    public DeviceResource(){
        deviceDao = new DeviceDao();
    }

    @GET
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML})
    public Device get(@QueryParam("ip") final String ip){
        return ip != null ? deviceDao.getDevice(ip) : null;
    }

    @PUT
    @Produces({MediaType.APPLICATION_JSON})
    @Consumes({MediaType.APPLICATION_JSON})
    public Device put(final Device device){
        return device != null ? deviceDao.updateDevice(device) : null;
    }
}
